package com.example.yiwei.crm.json;

import android.util.Log;

import com.example.yiwei.crm.entity.managerEntity;
import com.example.yiwei.crm.util.NetWorkUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/20.
 */

public class managerjson {

    public static List<managerEntity> jsonManager(String url, String para) {
        String result = NetWorkUtils.getCount(url, para);
        Log.d("aa",result);
        List<managerEntity> managerList=new ArrayList<>();
        try {
            JSONObject JSON = new JSONObject(result);
            boolean boolen = JSON.getBoolean("ifsuccess");
            if (boolen) {
                JSONArray array = JSON.getJSONArray("list");
                for (int i = 0; i < array.length(); i++) {
                    managerEntity manager=new managerEntity();
                    JSONObject json = array.getJSONObject(i);
                    if (json.has("UAB03")) {
                        manager.setManager_name(json.getString("UAB03"));
                    }
                    if (json.has("UAB01")){
                        manager.setManager_id(json.getInt("UAB01"));
                    }
                    if (json.has("UAB02")){
                        manager.setPersonal_number(json.getString("UAB02"));
                    }
                    if (json.has("UAA02")){
                        manager.setPersonal_number(json.getString("UAA02"));
                    }
                    if (json.has("UAA01")){
                        manager.setDepartment_id(json.getInt("UAA01"));
                    }
                    if (json.has("UAB04")){
                        manager.setManager_phone(json.getString("UAB04"));
                    }
                    if (json.has("UAB05")){
                        manager.setManager_address(json.getString("UAB05"));
                    }
                    if (json.has("UAB06")){
                        manager.setManager_job_id(json.getInt("UAB06"));
                    }
                    if (json.has("REK01")){
                        manager.setAdditional(json.getString("REK01"));
                    }
                    if (json.has("CTS01")){
                        manager.setCreate_time(json.getString("CTS01"));
                    }
                    if (json.has("UTS01")){
                        manager.setUpadate_time(json.getString("UTS01"));
                    }
                    if (json.has("CID01")){
                        manager.setCurrent_create_id(json.getInt("CID01"));
                    }
                    if (json.has("UID01")){
                        manager.setCurrent_update_id(json.getInt("UID01"));
                    }
                    if (json.has("UNT01")){
                        manager.setCurrent_medical_unit_id(json.getInt("UNT01"));
                    }
                    if (json.has("UNT02")){
                        manager.setCurrent_medical_unit_code(json.getString("UNT02"));
                    }
                    managerList.add(manager);
                }
                return managerList;

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return managerList;
    }
}
